<?php

class autocompleteDataAction extends sfActions
{
    public function execute($request)
    {
        $search = $request->getParameter('term', '');
        $type = $request->getParameter('type', null);
        if (!$type)
            throw new Exception('No type specified');

        $results = array();
        if($type === 'keywords') {
            $results = AutoComplete::getKeywords($search);

        }

        if($type === 'cities') {
            $country = $request->getParameter('country', null);
            $results = AutoComplete::getCities($country, $search);
        }

        if($type === 'college_major') {
            $results = AutoComplete::getCollegeMajors($search);
        }

        if($type === 'college_network') {
            $results = AutoComplete::getColleges($search);
        }

        if($type === 'work_network') {
            $results = AutoComplete::getWorkplaces($search);
        }

        $this->renderText($results);
        return sfView::NONE;
    }

}
